package utildb;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import utildb.Transaction;
import utildb.TransactionException;

public abstract class GenericDAO {
	protected Transaction transaction = null;
	protected PreparedStatement statement = null;
	protected Connection c;
	
	public GenericDAO() {
		super();
	}

	public GenericDAO(Transaction transacction) {
		this.transaction = transacction;
	}

	protected Transaction getTransaction() {
		return transaction;
	}

	public void ejecutarQuery(PreparedStatement statement, String mensaje) throws TransactionException {
		try {
			int n = statement.executeUpdate();
			statement.close();
			if (n == 0)
				throw new TransactionException(mensaje);
		} catch (SQLException e1) {
			throw new TransactionException(e1);
		}		
	}	
	public abstract void eliminar(String codigo) throws TransactionException;
}